﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

[assembly:CLSCompliant(true)]
namespace ArriviSoft.SlotMachine.Model
{
    public class SlotMachine
    {
        private int coins = 0;
        private ISlotValidator validator;
        private ISlotGenerator generator;

        public SlotMachine(ISlotGenerator generator, ISlotValidator validator)
        {
            this.generator = generator;
            this.validator = validator;
        }

        public int Coins
        {
            get { return this.coins; }
            private set { this.coins = value; }
        }

        /// <summary>
        /// Insert Coins in the machine
        /// </summary>
        /// <param name="value">A nuember of coins</param>
        public void InsertCoins(int value)
        {
            this.Coins += value;
        }

        public Outcome Play()
        {
            if (this.Coins == 0)
            {
                throw new InvalidOperationException("Insert coins before play again.");
            }
            else
            {
                this.Coins--;
            }

            int[] result = this.generator.Generate();

            return this.validator.Validate(result, generator.Figures);
        }
    }
}
